from instruction_re.core.datatypes import Preffix
from typing import List, Dict


def add_prefix(prefix: str, text: str):
    return prefix + text


def add_instruction_prefix(instruction: str):
    return Preffix.INSTRUCTION.value + instruction


def add_sentence_prefix(sentence: str):
    return Preffix.CONTEXT.value + sentence


def add_answer_prefix(answer: str):
    return Preffix.ANSWER.value + answer


def add_options_prefix(options: str):
    return Preffix.OPTIONS.value + options


def add_conditions_prefix(conditions: str):
    return Preffix.CONDITIONS.value + conditions


def add_examples_prefix(examples: str):
    return Preffix.EXAMPLES.value + examples


def format_str_list_to_a_string(str_list: List[str], sep: str = ","):
    if len(str_list) > 0:
        return sep.join(str_list) + "."
    return ""


# def format_options_list(options: List[str]):
#     return add_options_prefix(format_str_list_to_a_string(options))


def format_relations_to_type_extract_answer(relations: List[Dict[str, List[str]]]):
    # return TypeAnswerFormatter.from_relations(relations)
    unique_relation_types = list(set([r["type"] for r in relations]))

    answers = [
        r.lower() + " type exists in the sentence." for r in unique_relation_types
    ]

    return "".join(answers)
